package com.avocado.base.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.avocado.base.enums.AuthenticationLogResult;
import lombok.Data;


@Entity
@Table(name="AVO_AUTHENTICATION_LOG")
@JsonAutoDetect
@JsonIgnoreProperties(value={"handler","hibernateLazyInitializer"})
@Data
public class AuthenticationLog {
	@Id@Column(name="ID",nullable=false)
	@GeneratedValue(strategy = GenerationType.TABLE,generator="id_gen")
    @TableGenerator(name = "id_gen",pkColumnValue="AUTHENTICATION_LOG_ID",table="AVO_ID_GENERATOR", pkColumnName="GEN_NAME",valueColumnName="GEN_VALUE",allocationSize=1)
	private Long id;
	
	
	@Column(name="SESSION_ID")
	private String sessionId;
	
	
	@Column(nullable=false,name="ADDRESS")
	private String address;

	//因为用户可能用了一个不存在的用户或登录
	@Column(nullable=false,name="USER_NAME")
	private String userName;
	
	@Enumerated@Column(name="RESULT")
	private AuthenticationLogResult result=AuthenticationLogResult.SUCCESS;
	
	
	@ManyToOne(fetch=FetchType.EAGER)@JoinColumn(name="USER_ID")
	private User user;
	
	
	@Temporal(TemporalType.TIMESTAMP)@Column(nullable=false,name="CREATE_TIME")
	private Date createTime=new Date();
	
	@Temporal(TemporalType.TIMESTAMP)@Column(name="UPDATE_TIME")
	private Date updateTime;


	public Long getId() {
		return id;
	}


	

}
